<template>
	<div class="layout-pd">
		<el-table :data="state.tableData.data" v-loading="state.tableData.loading" style="width: 100%">
			<el-table-column prop="hid" label="id" width="300" />
			<el-table-column prop="name" label="作业名称"  width="300"></el-table-column>
			<!-- <el-table-column prop="roleSign" label="角色标识" show-overflow-tooltip></el-table-column>
				<el-table-column prop="sort" label="排序" show-overflow-tooltip></el-table-column> -->

			<!-- <el-table-column prop="describe" label="角色描述" show-overflow-tooltip></el-table-column> -->
			<el-table-column prop="endtime" :formatter="getLocalTime" label="截止时间"  width="400"></el-table-column>
		
			<el-table-column label="操作"  width="300">
				<template #default="scope">
					<el-button size="small" text type="primary" @click="Jump(scope)">查看</el-button>
					<!-- <el-button :disabled="scope.row.roleName === '超级管理员'" size="small" text type="primary" @click="onRowDel(scope.row)">删除</el-button>  -->
				</template>
			</el-table-column>
		</el-table>
	</div>
</template>

<script setup lang="ts" name="scriptfileupdouw">
import { storeToRefs } from 'pinia';
import { useUserInfo } from '/@/stores/userInfo';
import { onMounted, reactive, ref } from 'vue';
import { scriptApi } from '/@/api/fun/index';
import router from '/@/router';
import { Session } from '/@/utils/storage';
import { NextLoading } from '/@/utils/loading';



// 定义变量内容
const storesUserInfo = useUserInfo();
const { userInfos } = storeToRefs(storesUserInfo);
const userAuth = ref('');

// 定义变量内容
const state = reactive<SysRoleState>({
	tableData: {
		data: [],
		total: 0,
		loading: false,
		param: {
			hids: [],
			search: '',
			pageNum: 1,
			pageSize: 10,
			states: [],
			getatates:[],
		},
	},
});

// 初始化用户权限
const initUserAuth = () => {
	userAuth.value = userInfos.value.roles[0];
};


// 获取发布的作业
const onRadio = async () => {
	scriptApi().getHomeWork().then(res => {
		state.tableData.data = res.data;
		for (let i = 0; i < state.tableData.data.length; i++) {
			state.tableData.param.states.push(res.data[i].hid)
			Session.set(res.data[i].hid, JSON.stringify(res.data[i].content))
		}
		//获取作业状态
		scriptApi().getState(state.tableData.param.states).then(res => {
			 localStorage.setItem('states', JSON.stringify(res.data))
		})
		state.tableData.param.getatates=JSON.parse(localStorage.getItem("states") || '{}')
	})


};


//格式化后端返回来的时间
function getLocalTime(value: any) {
	let time = value.endtime[0] + '-' + value.endtime[1] + '-' + value.endtime[2] + ' ' + value.endtime[3] + ':' + value.endtime[4] + ':' + value.endtime[5]
	return time
}



//跳转到具体页面
const Jump = (scope: any) => {
	localStorage.setItem('hid', JSON.stringify(scope.row.hid))
	router.push("/funhomework")
}


// 页面加载时
onMounted(() => {
	initUserAuth()
	onRadio()
});


</script>



<!-- <template>
	<div class="layout-pd">
		<el-table :data="state.tableData.data" v-loading="state.tableData.loading" style="width: 100%">
			<el-table-column prop="hid" label="id" width="100" />
			<el-table-column prop="name" label="作业名称" show-overflow-tooltip></el-table-column>
			<el-table-column prop="endtime" label="截止时间" show-overflow-tooltip></el-table-column>
			<el-table-column prop="status" label="作业状态" show-overflow-tooltip>
				<template #default="scope">
					<el-tag type="info" v-if="scope.row.status">未提交</el-tag>
					<el-tag type="info" v-if="scope.row.status">待审核</el-tag>
					<el-tag type="info" v-if="scope.row.status">不合格</el-tag>
					<el-tag type="success" v-else>合格</el-tag>
				</template>
			</el-table-column>
			<el-table-column label="操作" width="100">
				<template #default="scope">
					<el-button size="small" text type="primary" @click="Jump(scope)">查看</el-button>
				</template>
			</el-table-column>
		</el-table>
	</div>
</template>

<script setup lang="ts" name="funCountup">
import Cookies from 'js-cookie';
import { storeToRefs } from 'pinia';
import { useUserInfo } from '/@/stores/userInfo';
import { Session } from '/@/utils/storage';
import { frontEndsResetRoute, setAddRoute, setFilterMenuAndCacheTagsViewRoutes } from '/@/router/frontEnd';
import { defineAsyncComponent, reactive, onMounted, ref } from 'vue';
import { scriptApi } from '/@/api/fun/index';
import { create } from 'sortablejs';
import { createDecipheriv } from 'crypto';
import { mount } from 'sortablejs';
import { on } from 'events';
import router from '/@/router';
// 定义变量内容
const storesUserInfo = useUserInfo();
const { userInfos } = storeToRefs(storesUserInfo);
const userAuth = ref('');

// 定义变量内容
const roleDialogRef = ref();
const state = reactive<SysRoleState>({
	tableData: {
		data: [],
		total: 0,
		loading: false,
		param: {
			search: '',
			pageNum: 1,
			pageSize: 10,
		},
	},
});
//获取所有作业

// 初始化用户权限
const initUserAuth = () => {
	userAuth.value = userInfos.value.roles[0];

};
// 用户权限改变时
const onRadioChange = async () => {
	// 清空之前缓存的 userInfo，防止不请求接口。
	// stores/userInfo.ts
	// Session.remove('userInfo');
	// // 模拟数据
	// frontEndsResetRoute();
	// Cookies.set('userName', userAuth.value);
	// // 模拟切换不同权限用户
	// await storesUserInfo.setUserInfos();
	// await setAddRoute();
	// setFilterMenuAndCacheTagsViewRoutes();
	scriptApi().getHomeWork().then(res => {
		state.tableData.data = res.data
	})

	let user = JSON.parse(localStorage.getItem ("user") || '{}')
	console.log(user)

};

const Jump = () => {
	localStorage.setItem('hid', JSON.stringify(scope.row.hid))
     router.push("/funhomework")
}
// 页面加载时
onMounted(() => {
	initUserAuth();
	onRadioChange()
});
</script> -->














<!-- <template>
	<div class="layout-pd">
		<el-card shadow="hover" header="数字滚动演示">
			<el-alert
				title="感谢优秀的 `countup.js`，项目地址：https://github.com/inorganik/countUp.js"
				type="success"
				:closable="false"
				class="mb15"
			></el-alert>
			<el-row :gutter="20">
				<el-col :sm="6" class="mb15" v-for="(v, k) in state.topCardItemList" :key="k">
					<div class="countup-card-item countup-card-item-box" :style="{ background: `var(${v.color})` }">
						<div class="countup-card-item-flex" ref="topCardItemRefs">
							<div class="countup-card-item-title pb3">{{ v.title }}</div>
							<div class="countup-card-item-title-num pb6"></div>
							<div class="countup-card-item-tip pb3">{{ v.tip }}</div>
							<div class="countup-card-item-tip-num"></div>
						</div>
						<i :class="v.icon" :style="{ color: v.iconColor }"></i>
					</div>
				</el-col>
			</el-row>
			<div class="flex-warp">
				<div class="flex-warp-item">
					<div class="flex-warp-item-box">
						<el-button type="primary" size="default" @click="refreshCurrent">
							<el-icon>
								<ele-RefreshRight />
							</el-icon>
							重置/刷新数值
						</el-button>
					</div>
				</div>
			</div>
		</el-card>
	</div>
</template>

<script setup lang="ts" name="funCountup">
import { reactive, onMounted, nextTick, ref } from 'vue';
import { CountUp } from 'countup.js';

// 定义变量内容
const topCardItemRefs = ref<RefType[]>([]);
const state = reactive({
	topCardItemList: [
		{
			title: '今日访问人数',
			titleNum: '123',
			tip: '在场人数',
			tipNum: '911',
			color: '--el-color-primary',
			iconColor: '#ffcb47',
			icon: 'iconfont icon-jinridaiban',
		},
		{
			title: '实验室总数',
			titleNum: '123',
			tip: '使用中',
			tipNum: '611',
			color: '--el-color-success',
			iconColor: '#70cf41',
			icon: 'iconfont icon-AIshiyanshi',
		},
		{
			title: '申请人数（月）',
			titleNum: '123',
			tip: '通过人数',
			tipNum: '911',
			color: '--el-color-warning',
			iconColor: '#dfae64',
			icon: 'iconfont icon-shenqingkaiban',
		},
		{
			title: '销售情况',
			titleNum: '123',
			tip: '销售数',
			tipNum: '911',
			color: '--el-color-danger',
			iconColor: '#e56565',
			icon: 'iconfont icon-ditu',
		},
	],
});

// 初始化数字滚动
const initNumCountUp = () => {
	nextTick(() => {
		topCardItemRefs.value.forEach((v: HTMLDivElement) => {
			new CountUp(v.querySelector('.countup-card-item-title-num') as HTMLDivElement, Math.random() * 10000).start();
			new CountUp(v.querySelector('.countup-card-item-tip-num') as HTMLDivElement, Math.random() * 1000).start();
		});
	});
};
// 重置/刷新数值
const refreshCurrent = () => {
	initNumCountUp();
};
// 页面加载时
onMounted(() => {
	initNumCountUp();
});
</script>

<style scoped lang="scss">
.countup-card-item {
	width: 100%;
	height: 103px;
	background: var(--el-text-color-secondary);
	border-radius: 4px;
	transition: all ease 0.3s;
	&:hover {
		box-shadow: 0 2px 12px 0 rgb(0 0 0 / 10%);
		transition: all ease 0.3s;
	}
}
.countup-card-item-box {
	display: flex;
	align-items: center;
	position: relative;
	overflow: hidden;
	&:hover {
		i {
			right: 0px !important;
			bottom: 0px !important;
			transition: all ease 0.3s;
		}
	}
	i {
		position: absolute;
		right: -10px;
		bottom: -10px;
		font-size: 70px;
		transform: rotate(-30deg);
		transition: all ease 0.3s;
	}
	.countup-card-item-flex {
		padding: 0 20px;
		color: var(--el-color-white);
		.countup-card-item-title,
		.countup-card-item-tip {
			font-size: 13px;
		}
		.countup-card-item-title-num {
			font-size: 18px;
		}
		.countup-card-item-tip-num {
			font-size: 13px;
		}
	}
}
</style> -->
